<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class LogCountEvent
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    protected $channel = 'channel-event';

    public $params;

    public function __construct($params)
    {
        $this->params = $params;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel($this->channel);
    }

    /**
     * Execute the event.
     *
     * @return bool
     */
    public function handle()
    {
        Log::channel('event')->info(__CLASS__ . ' handle : ' . json_encode($this->params, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));

        return true;
    }
}
